{% extends "template/layout.html" %} {% block content %}
<style>
    .admin_default {
        margin: 20px;
    }

    .layui-body {
        overflow-y: scroll;
    }

    .addBtn {
        float: right;
    }

    .addFrom {
        margin: 20px 20px 20px 5px;
    }

    .formBtn {
        margin-left: 150px;
        margin-top: 50px;
    }

    .idItem {
        display: none;
    }
    .searchBtn{
        margin:-5px 10px 10px 10px;
    }
    .noticeAdd {
        width: 230px;
        height: 35px;
    }
</style>

<div class="panel admin_default">
    <div class="demoTable">

        <div class="layui-input-inline">

            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">部门</label>
                    <div class="layui-input-block">
                        <select name="id" lay-filter="id" id="demoReload" autocomplete="off">
                            <option value=""></option>
                            {% for item in departmentList %}
                            <option value="{{item.id}}">{{item.name}}</option>
                            {% endfor%}
                        </select>

                    </div>
                </div>

            </form>
        </div>
        <button class="layui-btn searchBtn" data-type="reload">搜索</button>
        <button class="layui-btn  addBtn">添加</button>

    </div>

    <table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>


</div>


{% endblock %} {% block footer %}
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>
<script>
    layui.use(['form', 'table', 'laydate'], function () {
        var table = layui.table;
        var form = layui.form;
        //方法级渲染
        table.render({
            elem: '#LAY_table_user',
            url: '/employees/list',
            cols: [
                [{
                        field: 'id',
                        title: 'ID',
                        width: 150,
                        sort: true,
                        fixed: true
                    }, {
                        field: 'num',
                        title: '员工编号',
                        align: 'center',
                    }, {
                        field: 'name',
                        title: '姓名',
                        align: 'center',
                    }, {
                        field: 'departmentName',
                        title: '所属部门',
                        align: 'center',
                    }, {
                        field: 'createdAt',
                        title: '发布时间',
                        align: 'center',
                    },
                    {
                        fixed: 'right',
                        title: '操作',
                        width: 178,
                        align: 'center',
                        toolbar: '#barDemo'
                    }
                ]
            ],
            id: 'testReload',
            page: true
        });

        var $ = layui.$,
            active = {
                reload: function () {
                    var demoReload = $('#demoReload');

                    //执行重载
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        },
                        where: {
                                id: demoReload.val()
                        }
                    });
                }
            };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听工具条  
        table.on('tool(user)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确认删除此条数据', function (index) {
                    var delData = data;
                    $.post('/employees/del', delData, function (res) {
                        if (res.status == 200) {
                            obj.del();
                            layer.close(index);
                        }
                    })

                });
            } else if (obj.event === 'detail') { //详情界面
                var noticeId = data.id;
                window.location.href = '/employees/detail/' + noticeId
            } else if (obj.event === 'edit') { //修改界面
                var noticeId = data.id;
                window.location.href = '/employees/edit/' + noticeId
            }
        });
        $(".addBtn").click(function () {
            window.location.href = "/employees/add"
        })
    });
</script>
{% endblock %}